

function ieMaxWidthPatch() {
	var browser = navigator.appName;

	if (browser == "Microsoft Internet Explorer") {
		var gentableArr = document.getElementsByTagName("table");

		for ( var i = 0; i < gentableArr.length; i++) {
			var gentable = gentableArr[i];

			if (gentable.className == "gen_table") {
				var tablerows = gentable.rows;
				for ( var k = 0; k < tablerows.length; k++) {
					var tablecells = tablerows[k].cells;
					for ( var p = 0; p < tablecells.length; p++) {
						if (tablecells[p].innerHTML.length > 30) {
							tablecells[p].width = "200px";
						}
					}
				}
			}
		}

	}
}

function emptyCombo(comboBox) {
	while ( comboBox.firstChild ) {
		comboBox.removeChild(comboBox.firstChild);
	}
	
}

function remove(id){
	var oNodeToRemove = document.getElementById(id);
	var aParentNode=oNodeToRemove.parentNode;
	var index=0;
	for(var i=0;i<aParentNode.rows.length;i++) {
		if(aParentNode.rows[i].id==oNodeToRemove.id){
			index=i;
			break;
		}
	}
	aParentNode.removeChild(oNodeToRemove);
	if(aParentNode.rows.length==0) {
		var tbl=aParentNode.parentNode;
		var parentOfTable=tbl.parentNode;
		parentOfTable.removeChild(tbl);
		
	}
	return index;
}

function getRealIndex(id){
	var oNodeToRemove = document.getElementById(id);
	var aParentNode=oNodeToRemove.parentNode;
	var index=0;
	for(var i=0;i<aParentNode.rows.length;i++) {
		if(aParentNode.rows[i].id==oNodeToRemove.id){
			index=i;
			break;
		}
	}
	
	return index;
}

function isNoRowLeft(trParent){
	if(trParent==null){
		return true;
	}
	if(trParent.rows.length==0) {
		return true;
	}
	return false;
}

function removeElement(id){
	var oNodeToRemove = document.getElementById(id);
	if(oNodeToRemove==null){
		return;
	}
	var aParentNode=oNodeToRemove.parentNode;
	aParentNode.removeChild(oNodeToRemove);
}

function addOption(combo, value, text){
	var anOption = document.createElement('OPTION');
	anOption.innerHTML=text;
	anOption.value=value;
	combo.appendChild(anOption);
}

function buttonHov(btn) {
	
	if(btn.className.indexOf("disabled") >= 0){
		return;
	}
	if(btn.className.indexOf("sm") < 0){
		btn.className="enabled_button_hov";
	} else {
		btn.className="enabled_button_sm_hov";
	}
}

function buttonHout(btn) {
	if(btn.className.indexOf("disabled") >= 0){
		return;
	}
	if(btn.className.indexOf("sm") < 0){
		btn.className="enabled_button";
	} else {
		btn.className="enabled_button_sm";
	}
}

function isBtnDisabled(btn){
	if(btn.className.indexOf("disabled") >= 0){
		return true;
	}
	
	return false;
}

function lock(btn){
	if(btn.className.indexOf("disabled") >= 0){
		return;
	}
	if(btn.className.indexOf("sm") < 0){
		btn.className="disabled_button";
	} else {
		btn.className="disabled_button_sm";
	}

}

function unlock(btn){
	if(btn.className.indexOf("enabled") >= 0){
		return;
	}
	if(btn.className.indexOf("sm") < 0){
		btn.className="enabled_button";
	} else {
		btn.className="enabled_button_sm";
	}

}

function iconHov(component) {
	component.src="images/calendar_hov.jpeg";
}
function iconHout(component){
	component.src="images/calendar.jpeg";
}
function sort(thObj) {
	
	
}


function menuHov(menuItem) {
	menuItem.className="side_menu_hov";
}

function menuHout(menuItem) {
	menuItem.className="";
}

function getMessageSpan(component) {
	var pnode=component.parentNode;
	var messageSpan;
	
	if(pnode.getElementsByTagName("LABEL").length!=0){
		messageSpan=pnode.getElementsByTagName("LABEL")[0];
		messageSpan.innerHTML="";
		messageSpan.className="";
	} else {
		messageSpan = document.createElement('LABEL');
		//var patt=/\w{1,5}/g;
		//patt.test(component.value)==true
	}	
	return messageSpan;
	
}
function setMessage(component, message, className){
	var messageSpan = getMessageSpan(component);
	var pnode=component.parentNode;
	pnode.appendChild(messageSpan);
	messageSpan.innerHTML=message;
	messageSpan.className=className;
}

function showError(component, message) {
	setMessage(component,message,"errorbox");
}

function showErrorOnTop(message) { 
	var messageBox = document.getElementById('messageBox').value;
	messageBox.className='errordiv';
	messageBox.innerHTML=message;
}

function showWarning(component, message) {
	setMessage(component,message,"warningbox");
}

function showSuccess(component, message) {
	setMessage(component,message,"successbox");
}

function showInfo(component, message) {
	setMessage(component,message,"infobox");
}

function clean(component) {
	if(component != null){
		setMessage(component,"","");
	}
}


function trim(str) {
	
		return str.replace(/^\s+|\s+$/g,"");
	
}



function FormatNumberBy3(num, decpoint, sep) {
// check for missing parameters and use defaults if so
if (arguments.length == 2) {
 sep = ",";
}
if (arguments.length == 1) {
 sep = ",";
 decpoint = ".";
}
// need a string for operations
num = num.toString();
// separate the whole number and the fraction if possible
a = num.split(decpoint);
x = a[0]; // decimal
y = a[1]; // fraction
z = "";


if (typeof(x) != "undefined") {
 // reverse the digits. regexp works from left to right.
 for (i=x.length-1;i>=0;i--)
   z += x.charAt(i);
 // add seperators. but undo the trailing one, if there
 z = z.replace(/(\d{3})/g, "$1" + sep);
 if (z.slice(-sep.length) == sep)
   z = z.slice(0, -sep.length);
 x = "";
 // reverse again to get back the number
 for (i=z.length-1;i>=0;i--)
   x += z.charAt(i);
 // add the fraction back in, if it was there
 if (typeof(y) != "undefined" && y.length > 0)
   x += decpoint + y;
}
return x;
}

function getXmlHttpObject() {
	var xhr=null;
	try  {
	  // Firefox, Opera 8.0+, Safari
		xhr=new XMLHttpRequest();
	  } 	catch (e)	  {
	  // Internet Explorer
	  try    {
		  xhr=new ActiveXObject("Msxml2.XMLHTTP");
	   }  catch (e)   {
		   xhr=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	  
	return xhr;
}

function getPostObject(url,params) {
	var xhr=getXmlHttpObject();
	if(!xhr){
		return false;
	}
	if(params == null){
		params="";
	}
	params += "&areq=true";
	xhr.open('POST',url, false);
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length", params.length);
	xhr.setRequestHeader("Connection", "close");
	xhr.send(params);
	return xhr;
}

function isErrorOccured(result) {
	if(result != null ) {
		if(result.indexOf("error|") >= 0) {
			return true;
		}
	}
	return false;
}

function getErrorMessage(result) {
	if(result != null ) {
		if(result.indexOf("error|") >= 0) {
			var arr = result.split("|");
			if(arr.length > 1){
				return arr[1];
			}
		}
	}
	return "ERROR";
}

function popHelp(index) {
	
	var path = "help.jsp#" + index;
	window.open(path, "TAPHELP", 'width=450,height=580,scrollbars=yes,resizable=yes,dependent=yes, left=600,top=0');

}

function popHelpByUrl(url) {
	
	var temp = new Array();
	var myUrl = url;
	temp = myUrl.split('/');
	url = temp[2];

	var path = "help.jsp#" + url;
	window.open(path, "TAPHELP", 'width=450,height=580,scrollbars=yes,resizable=yes,dependent=yes, left=600,top=0');

}

function openLog(id, type) {
	var path = "entity_log.jsp?id=" + id + "&type=" + type;
	window.open(path, "ADZon", 'width=800,height=580,scrollbars=yes,resizable=yes,dependent=yes, left=600,top=0');
}

function disableForm() {
     var w=document.body.offsetWidth;    
	 var h=document.body.offsetHeight;
	 
	
	 var newdiv = document.createElement('div');
	 newdiv.id='disabledStyle';
	 newdiv.className ='disabledStyle';
	 newdiv.style.width=w;
	 newdiv.style.height=h;
	 
	 var newiframe = document.createElement('iframe');
	 newiframe.id='disablediframeStyle';
	 newiframe.scrolling='no';
	 newiframe.frameborder='0';
	 newiframe.className ='disablediframeStyle';
	 newiframe.width=w;
	 newiframe.height=h;
	 newdiv.appendChild(newiframe);
	 
	 document.body.appendChild(newdiv);
	 document.body.style.overflow='hidden';
}


function popupPreview(id) {
	var hre = "popup_media.jsp?id="+id;
	window.open(hre, "PreviewMedia"+id,'width=660,height=500,left=100,top=100,scrollbars=yes,resizable=yes,dependent=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

function openReportingPopup(href){
	window.open(href, "Reporting", 'channelmode=yes,type=fullWindow,location=yes,status=yes,resizable=yes,scrollbars=yes,width=1000,height=600');
}
